from selenium.webdriver.common.by import By
from pages.base_page import BasePage

class AddContactsPage(BasePage):
    """客户-联系人-新建联系人页面做的操作"""
    # 填写必选项
    input_contacts_name_locator = (By.CSS_SELECTOR, '#name')  # 填写联系人为12个字符
    click_client_locator = (By.NAME, 'customer_name')  # 点击客户
    select_client_locator = (By.XPATH, '//*[@id="datas"]/tr/td[1]/input[1]')  # 选择客户框
    click_sure_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    input_qq_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input')
    click_save_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)')
    add_successful_tips=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    input_special_phone_locator = (By.CSS_SELECTOR,
                                   'body > div.container > div.row > div > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input')
    def input_contacts_name(self,contacts_name):
        """填写联系人姓名"""
        self.driver.find_element(*self.input_contacts_name_locator).send_keys(contacts_name)

    def click_client_btn(self):
        """点击客户"""
        self.driver.find_element(*self.click_client_locator).click()

    def select_cilent_box(self):
        """选择客户框"""
        self.driver.find_element(*self.select_client_locator).click()

    def click_save_btn(self):
        """点击保存"""
        self.driver.find_element(*self.click_sure_locator).click()  # 点击确定

    def input_qq(self,qq):
        """填写11位QQ号"""
        self.driver.find_element(*self.input_qq_locator).send_keys(qq)

    def input_special_phone(self,special_phone):
        """填写含有特殊字符的手机号"""
        self.driver.find_element(*self.input_special_phone_locator).send_keys(special_phone)

    def click_save(self):
        """点击保存"""
        self.driver.find_element(*self.click_save_locator).click()

    def successful_tips(self):
        """断言添加成功字样"""
        add_tips=self.driver.find_element(*self.add_successful_tips).text
        return add_tips
